package com.powernode.work.service.impl;

import com.powernode.commons.utils.DateUtils;
import com.powernode.commons.utils.ResponseData;
import com.powernode.commons.utils.UUIDUtils;
import com.powernode.work.bean.ActivityRemarkBean;
import com.powernode.work.dao.ActivityRemarkMapper;
import com.powernode.work.service.ActivityRemarkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class ActivityRemarkServiceImpl implements ActivityRemarkService {
    @Autowired
    private ActivityRemarkMapper dao;

    /**
     * 根据市场活动的主键查询备注列表
     * @param activityId
     * @return
     */
    @Override
    public ResponseData findByActivityId(String activityId) {
        return ResponseData.ok(dao.selectByActivityId(activityId));
    }

    /**
     * 添加备注
     * @param remark
     * @return
     */
    @Override
    public ResponseData add(ActivityRemarkBean remark) {
        //设置主键
        remark.setId(UUIDUtils.getUUID());
        //设置创建时间
        remark.setCreateTime(DateUtils.formatDateTime(new Date()));
        int row = dao.insertSelective(remark);
        if (row>0){
            return ResponseData.ok();
        }
        return ResponseData.error();
    }

    /**
     * 修改备注
     * @param remark
     * @return
     */
    @Override
    public ResponseData modify(ActivityRemarkBean remark) {
        //设置修改时间
        remark.setEditTime(DateUtils.formatDateTime(new Date()));
        int row = dao.updateByPrimaryKeySelective(remark);
        if (row>0){
            return ResponseData.ok();
        }
        return ResponseData.error();
    }

    /**
     * 根据主键删除备注
     * @param remarkId
     * @return
     */
    @Override
    public ResponseData remove(String remarkId) {
        int row = dao.deleteByPrimaryKey(remarkId);
        if (row>0){
            return ResponseData.ok();
        }
        return ResponseData.error();
    }
}
